from cryptography import fernet
from cryptography.fernet import Fernet


def encrypt(filename, key):
    fernet = Fernet(key)
    with open(filename, 'rb') as file:
        original = file.read()
    encrypted = fernet.encrypt(original)
    with open(filename, 'wb') as dec_file:
        dec_file.write(encrypted)


def decrypt(filename, key):
    fernet = Fernet(key)
    with open(filename, 'rb') as enc_file:
        encrypted = enc_file.read()
    decrypted = fernet.decrypt(encrypted)
    with open(filename, 'wb') as dec_file:
        dec_file.write(decrypted)

key = Fernet.generate_key()
filename = 'file.txt'

if __name__ == '__main__':
    print(key)
    #encrypt(filename, key)
    decrypt(filename, 'kpbxfuUuaoViYK6HI2mqa2vfVubMTxzjkj5EDCgfnvk=')
